<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>预定商品列表</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(function(){
            //加载总价合计
            $("td[name=total]").each(function(){
                var price =  parseFloat($(this).prev("td").html());
                var quantity =  parseFloat($(this).prev("td").prev("td").html());
                var total = parseFloat(parseFloat(quantity*price).toFixed(2));
                $(this).html(total);
            });
            $("#ids").on("change",function(){
                var flag = $(this).prop("checked");
                if(flag){//全选
                    $("input[name='agentProductId']").each(function(){
                        $(this).prop("checked","checked");
                    })
                }else{
                    $("input[name='agentProductId']").each(function(){
                        $(this).prop("checked","");
                    })
                }
            })
        })
        function shop() {
           // alert(1);
            var checkbox = $("input[name='agentProductId']");
            var abc='';
            //先校验是否有被选中的
            $("input[name='agentProductId']").each(function(){
                var checked = $(this).prop("checked");
                if(checked){
                    var id = $(this).val();
                    var numVal=$("#"+id).parent().parent().find("td[name=quantity]").html();
                    abc=abc+id+','+numVal+';';
                }
            })
            if(abc==''){
                alert("请选择下单商品");
                return ;
            }
            $("#btn").attr("disabled", true);
            var remarks = "下单";
            $("#btnSubmitOne").prop("disabled", true);
            $.ajax({
                type:'post',
                url:'${ctx}/sys/tbShopController/buyAgentProduct',
                data:{"str":abc,"remarks":remarks},
                dataType:"JSON",
                success:function(a){
                    var url = a.orderUrl;
                    var orderId = a.id;
                    var agentId = a.agentName;
                    var productType=a.productType;
                    //alert("生活预定"+productType);
                    window.location.href="saoma?urlApply="+url+"&orderId="+orderId+"&agentId="+agentId+"&type=1&productType="+productType;
                },
                error:function(b){
                    alert("下单失败");
                    $("#btnSubmitOne").prop("disabled", false);
                }
            });
        }
        function page(n, s) {
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").attr("action", "${ctx}/sys/tbShopController/reverseProductOrderList");
            $("#searchForm").submit();
            return false;
        }

    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/sys/tbShopController/reverseProductOrderList">预定商品列表</a></li>
</ul>
<form:form id="searchForm" modelAttribute="reverseProduct" action="${ctx}/sys/tbShopController/reverseProductOrderList"
           method="post" class="breadcrumb form-search">
    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
    <label>商品名称：&nbsp;</label>
    <input id="title" name="title" type="text"  maxlength="20" value="${reverseProduct.title}"/> &nbsp;
    <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
    <input id="btnSubmitOne" class="btn btn-primary" type="button" value="一键下单"  onclick="shop()"/>
</form:form>
<sys:message content="${message}"/>
<span><font style="color: #00A6C7">${message1}</font></span>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
        <tr>
            <%--<th width="5%">商品图片</th>--%>
            <th width="15%">商品名称</th>
            <th width="15%">规格</th>
            <th width="20%">预定开始时间</th>
            <th width="20%">预定结束时间</th>
            <th width="5%">数量</th>
            <th width="5%">进货价格</th>
            <th width="10%">总价</th>
            <th width="2%"><input type="checkbox" id="ids" /></th>
        </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="reverseProduct">
        <tr>
            <%--<td><img src="${reverseProduct.showUrl}" style="width:50%"/></td>--%>
            <td>${reverseProduct.title}</td>
            <td>${reverseProduct.attr}</td>
            <td>${reverseProduct.reverseStartTime}</td>
            <td>${reverseProduct.reverseEndTime}</td>
            <td name="quantity">${reverseProduct.quantity}</td>
            <td>${reverseProduct.price}</td>
            <td name="total"></td>
            <td>
                <input type="checkbox" name="agentProductId"  value="${reverseProduct.agentProductId}" id="${reverseProduct.agentProductId}" >
                <input type="hidden" name="agentProductId" id="${reverseProduct.agentProductId}" value="${reverseProduct.agentProductId}" >
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${page}</div>
</body>
</html>
